package com.thf.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Tool {
    private Tool() {
    }

    public static Integer stringToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return 0;
    }

    public static Integer curPageToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return 1;
    }

    public static Integer pageSizeToInt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (Exception e) {

        }
        return 10;
    }

    public static Float stringToFloat(String value) {
        try {
            return Float.parseFloat(value);
        } catch (Exception e) {

        }
        return 0f;
    }
    public static String jsonToString(Object obj) {
      if(obj == null) {
          String str = "";
          return str ;
      }
        return (String) obj;
    }
    public static String dateToString(Date date) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        return format;
    }
    public static String StringToNotNull(String str) {
        if( "".equals(str)) {
            return "0" ;
        }
        return (String) str;
    }
}
